 <!DOCTYPE html>
<html lang="en">
<head>
<#include "/WEB-INF/views/admin/common/inc/_css.html">
<link rel="stylesheet" href="${ctx}/resource/validationengine/css/validationEngine.jquery.css">
<link rel="stylesheet" href="${ctx}/resource/zTree/css/zTreeStyle/zTreeStyle.css">

<#include "/WEB-INF/views/admin/common/inc/_header_js.html">
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine.js"></script>
<script type="text/javascript" src="${ctx}/resource/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${ctx}/resource/zTree/js/jquery.ztree.excheck.js"></script> <script type="text/javascript">
	$(function() {
		$.ajax({
			type : "POST",
			url : "${ctx}/admin/sys/res/getZtreeViewList",
			dataType : 'json',
			data :{"roleId":"${roleId!}","type":"${type!}"},
			success : function(msg) {
				$.fn.zTree.init($("#treeDemo"), setting, msg);
				zTree_Menu = $.fn.zTree.getZTreeObj("treeDemo");
			}
		});
		
		$("#saveBtn").click(function(){
			$("#saveBtn").attr("disabled","disabled");
			var nodes = zTree_Menu.getCheckedNodes(true);
			var selectIds="";
			for(var index in nodes){
				var item=nodes[index];
				selectIds+=item.id+",";
			} 
			
			var submitData={
					"menuIds":selectIds,
					"roleId":"${roleId!}"
			}
			$.ajax({
				type : "POST",
				url : "${ctx}/admin/sys/role/saveMenuAssign",
				dataType : 'json',
				data :submitData,
				success : function(data){
					$("#saveBtn").removeAttr("disabled");
					if(data.isSuccess){
						layer.msg("保存成功", {
						    icon: 1,
						    time: 1000 //1秒关闭（如果不配置，默认是3秒）
						});
					}else{
						layer.msg(data.msg, {
						    icon: 2,
						    time: 1000 //1秒关闭（如果不配置，默认是3秒）
						});
					}
				}
			});
		});
	});
	var setting = {
		check : {
			enable : true
		},
		data : {
			simpleData : {
				enable : true
			}
		},
		callback : {
			beforeCheck : beforeCheck,
			onCheck : onCheck
		}
	};
	function beforeCheck(treeId, treeNode) {
		return (treeNode.doCheck !== false);
	}
	function onCheck(e, treeId, treeNode) {
	}
	setting.check.chkboxType = {
		"Y" : "ps",
		"N" : "s"
	};
</script>
</head>
<body data-type="widgets">
 <script src="${ctx}/resource/amazeuiadmin/assets/js/theme.js"></script>
	<div class="tpl-content-wrapper">
		<div class="row-content am-cf">
			<div class="row">
				<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
					<div class="widget am-cf">
						<div class="widget-head am-cf">
							<div class="widget-title  am-cf">资源分配</div>
						</div>
						<div class="widget-body  am-fr">
							<div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
								<div>
									<ul id="treeDemo" class="ztree"></ul>
								</div>
								<hr>
								<div class="am-fr">
									<button type="button" class="am-btn am-btn-default am-btn-success" id="saveBtn">
										提交
									</button>
								</div>
							</div>
		              </div>
					</div>
				</div>
			</div>
		</div>
	</div>
 <#include "/WEB-INF/views/admin/common/inc/_foot_js.html">
</body>
</html>
